package com.haotian.log.biz;

import java.util.HashMap;
import java.util.Map;

import org.apache.log4j.Logger;

/**
 * 使用单利对象操作经分，从而达到文件的线程安全 基于org.apache.log4j
 * 
 * @author 张昊天 2017年12月7日
 */
public final class _BizLogUtils {

	private _BizLogUtils() {
		
	}

	private final static Map<String, Logger> cache = new HashMap<String, Logger>();

	public synchronized final static Logger getLogger(String name) {

		Logger logger = cache.get(name);

		if (logger == null) {
			logger = Logger.getLogger(name);
			cache.put(name, logger);
		}

		return logger;
	}

	public synchronized final static Logger getLogger(Class<?> clazz) {

		Logger logger = cache.get(clazz.getName());

		if (logger == null) {
			logger = Logger.getLogger(clazz);
			cache.put(clazz.getName(), logger);
		}

		return logger;
	}

}
